/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.gps.service;

import java.util.Date;
import java.util.TimerTask;
import pe.gps.server.GPSFactory;

/**
 *
 * @author romulogalindo
 */
public class ServicioSO_STADISTIC extends ServicioSO {

    public ServicioSO_STADISTIC(String no_server, int ti_eject) {
        super(no_server, ti_eject);
        no_descrip = "Actualiza los datos estadisticos";
    }

    @Override
    public void start() {
        System.out.println("[ServicioSO_STADISTIC] Iniciado[" + getNo_server() + "]");
    }

    @Override
    public void stop() {
        System.out.println("[ServicioSO_STADISTIC] Detenido[" + getNo_server() + "]");
        try {
            timer.cancel();
            timer.purge();
            timer = null;
        } catch (Exception ep) {
            System.out.println("[ServicioSO_STADISTIC] Detenido :erro [" + ep.getMessage() + "]");
        }
    }

    @Override
    public void run() {
        System.out.println("[ServicioSO_STADISTIC] RUN[" + getNo_server() + "]");
        timer.scheduleAtFixedRate(new SO_STADISTIC(), getTi_eject() * 1000, getTi_eject() * 1000);
    }

    @Override
    public void updateCa_exec() {
        ca_exec++;
    }

    @Override
    public void updateFe_ultexec() {
        fe_ultexec = new Date();
    }

    @Override
    public void updateNo_descrip() {
        no_descrip = "Actualiza los datos estadisticos";
    }
    
    public class SO_STADISTIC extends TimerTask{

        @Override
        public void run() {
            GPSFactory.getServer().update_info();
            updateCa_exec();
            updateFe_ultexec();
        }
        
    }

}
